/***************************************************************************
创建者：华磊
 开始时间：               : 2020.1１.２４
 copyright            : (C) 深圳市华友高科有限公司
 修改说明：（每次有修改就添加一条，带有 修改人，修改时间，修改描述）

 ***************************************************************************
 *   io窗口程序
*                                                                         *
 ***************************************************************************/
#include "systemstatus.h"
#include "ui_systemstatus.h"


SystemStatus::SystemStatus(int styleId,QWidget *parent):
    QWidget(parent),
    ui(new Ui::SystemStatus)
{
    ui->setupUi(this);

    nowSysVIewID = EM_SYS_VIEW_DI;

    //setGeometry(0,0,460,595);
    setGeometry(75,130,460,595);
    initialDisplayStyle(styleId);

    aiStatusView=new AiStatus(styleId);
    aoStatusView=new AoStatus(styleId);
    diStatusView=new DiStatus(styleId);
    doStatusView=new DoStatus(styleId);
    generalStatusView=new GeneralStatus(styleId);
    globalRegisterStatusView=new GlobalRegisterStatus(styleId);
    palletRegisterStatusView=new PalletRegisterStatus(styleId);
    pointRegisterStatusView=new PointRegisterStatus(styleId);
    registerStatusView=new RegisterStatus(styleId);
    siStatusView=new SiStatus(styleId);
    soStatusView=new SoStatus(styleId);
    timerStatusView=new TimerStatus(styleId);

    aiStatusView->systemStatus=this;
    aoStatusView->systemStatus=this;
    diStatusView->systemStatus=this;
    doStatusView->systemStatus=this;
    generalStatusView->systemStatus=this;
    palletRegisterStatusView->systemStatus=this;
    pointRegisterStatusView->systemStatus=this;
    registerStatusView->systemStatus=this;
    siStatusView->systemStatus=this;
    soStatusView->systemStatus=this;
    timerStatusView->systemStatus=this;
    globalRegisterStatusView->systemStatus=this;

    aiStatusView->setParent(this);
    aiStatusView->hide();
    aoStatusView->setParent(this);
    aoStatusView->hide();
    diStatusView->setParent(this);
    diStatusView->show();               //默认初始显示
    ui->dibutton->setDisabled(true);    //初始选中
    doStatusView->setParent(this);
    doStatusView->hide();
    generalStatusView->setParent(this);
    generalStatusView->hide();
    palletRegisterStatusView->setParent(this);
    palletRegisterStatusView->hide();
    pointRegisterStatusView->setParent(this);
    pointRegisterStatusView->hide();
    registerStatusView->setParent(this);
    registerStatusView->hide();
    siStatusView->setParent(this);
    siStatusView->hide();
    soStatusView->setParent(this);
    soStatusView->hide();
    timerStatusView->setParent(this);
    timerStatusView->hide();
    globalRegisterStatusView->setParent(this);
    globalRegisterStatusView->hide();
}

SystemStatus::~SystemStatus()
{
    delete ui;
}

void SystemStatus::initialDisplayStyle(int styleId)
{
    switch (styleId) {
    case 1:
        setGeometry(0,0,600,450);
        ui->dibutton->setGeometry(470,15,55,50);
        ui->dobutton->setGeometry(540,15,55,50);
        ui->sibutton->setGeometry(470,75,55,50);
        ui->sobutton->setGeometry(540,75,55,50);
        ui->aibutton->setGeometry(470,135,55,50);
        ui->aobutton->setGeometry(540,135,55,50);
        ui->aibutton_2->setGeometry(470,195,55,50);
        ui->rbutton->setGeometry(540,195,55,50);
        ui->prbutton->setGeometry(470,255,55,50);
        ui->plbutton->setGeometry(540,255,55,50);
        ui->timerbutton->setGeometry(470,315,55,50);
        ui->pushButton->setGeometry(540,315,55,50);
        break;
    default:
        break;
    }
}

void SystemStatus::on_dibutton_clicked()
{
    hideAllStatus();
    diStatusView->show();
    nowSysVIewID = EM_SYS_VIEW_DI;
    ui->dibutton->setDisabled(true);
}

void SystemStatus::on_dobutton_clicked()
{
    hideAllStatus();
    doStatusView->show();
    nowSysVIewID = EM_SYS_VIEW_DO;
    ui->dobutton->setDisabled(true);
}

void SystemStatus::on_sibutton_clicked()
{
    hideAllStatus();
    siStatusView->show();
    nowSysVIewID = EM_SYS_VIEW_SI;
    ui->sibutton->setDisabled(true);
}

void SystemStatus::on_sobutton_clicked()
{
    hideAllStatus();
    soStatusView->show();
    nowSysVIewID = EM_SYS_VIEW_SO;
    ui->sobutton->setDisabled(true);
}

void SystemStatus::on_aibutton_clicked()
{
    hideAllStatus();
    aiStatusView->show();
    nowSysVIewID = EM_SYS_VIEW_AI;
    ui->aibutton->setDisabled(true);
}

void SystemStatus::on_aobutton_clicked()
{
    hideAllStatus();
    aoStatusView->show();
    nowSysVIewID = EM_SYS_VIEW_AO;
    ui->aobutton->setDisabled(true);
}

void SystemStatus::on_rbutton_clicked()
{
    hideAllStatus();
    registerStatusView->show();
    nowSysVIewID = EM_SYS_VIEW_R;
    ui->rbutton->setDisabled(true);
}

void SystemStatus::on_prbutton_clicked()
{
    hideAllStatus();
    pointRegisterStatusView->show();
    nowSysVIewID = EM_SYS_VIEW_PR;
    ui->prbutton->setDisabled(true);
}

void SystemStatus::on_plbutton_clicked()
{
    hideAllStatus();
    palletRegisterStatusView->show();
    nowSysVIewID = EM_SYS_VIEW_PL;
    ui->plbutton->setDisabled(true);
}

void SystemStatus::on_timerbutton_clicked()
{
    hideAllStatus();
    timerStatusView->show();
    nowSysVIewID = EM_SYS_VIEW_TIME;
    ui->timerbutton->setDisabled(true);
}

void SystemStatus::on_aibutton_2_clicked()//GR
{
    hideAllStatus();
    globalRegisterStatusView->show();
    nowSysVIewID = EM_SYS_VIEW_GR;
    ui->aibutton_2->setDisabled(true);
}

void SystemStatus::on_pushButton_clicked()
{
    hideAllStatus();
    generalStatusView->show();
    nowSysVIewID = EM_SYS_VIEW_G;
    ui->pushButton->setDisabled(true);
}

void SystemStatus::hideAllStatus()
{
    aiStatusView->hide();
    aoStatusView->hide();
    diStatusView->hide();
    doStatusView->hide();
    generalStatusView->hide();
    palletRegisterStatusView->hide();
    pointRegisterStatusView->hide();
    registerStatusView->hide();
    siStatusView->hide();
    soStatusView->hide();
    timerStatusView->hide();
    globalRegisterStatusView->hide();

    //disable = 未选中状态
    ui->aibutton->setDisabled(false);
    ui->aobutton->setDisabled(false);
    ui->dibutton->setDisabled(false);
    ui->dobutton->setDisabled(false);
    ui->sibutton->setDisabled(false);
    ui->sobutton->setDisabled(false);
    ui->timerbutton->setDisabled(false);
    ui->aibutton_2->setDisabled(false);
    ui->rbutton->setDisabled(false);
    ui->prbutton->setDisabled(false);
    ui->plbutton->setDisabled(false);
    ui->pushButton->setDisabled(false);
}

void SystemStatus::changeLanguage(int language)
{
    if(1 == language)
    {
        translator.load("/agvwork/AgvHmi/baseBag/hmiProject/language/systemStatusEnglishLan.qm");
        qApp->installTranslator(&translator);
    }
    else
    {
        qApp->removeTranslator(&translator);
    }
    ui->retranslateUi(this);

    aiStatusView->changeLanguage();
    aoStatusView->changeLanguage();
    diStatusView->changeLanguage();
    doStatusView->changeLanguage();
    generalStatusView->changeLanguage();
    globalRegisterStatusView->changeLanguage();
    palletRegisterStatusView->changeLanguage();
    pointRegisterStatusView->changeLanguage();
    registerStatusView->changeLanguage();
    siStatusView->changeLanguage();
    soStatusView->changeLanguage();
    timerStatusView->changeLanguage();
}
